home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / FLTK-1.0.6 / src / fl_set_font.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-07  |  2.3 KB  |  76 lines

  1. //
  2. // "$Id: fl_set_font.cxx,v 1.5 1999/01/07 19:17:42 mike Exp $"
  3. //
  4. // Font utilities for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-1999 by Bill Spitzak and others.
  7. //
  8. // This library is free software; you can redistribute it and/or
  9. // modify it under the terms of the GNU Library General Public
  10. // License as published by the Free Software Foundation; either
  11. // version 2 of the License, or (at your option) any later version.
  12. //
  13. // This library is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16. // Library General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Library General Public
  19. // License along with this library; if not, write to the Free Software
  20. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  21. // USA.
  22. //
  23. // Please report all bugs and problems to "fltk-bugs@easysw.com".
  24. //
  25.  
  26. // Add a font to the internal table.
  27. // Also see fl_set_fonts.C which adds all possible fonts.
  28.  
  29. #include <config.h>
  30. #include <FL/Fl.H>
  31. #include <FL/x.H>
  32. #include "Fl_Font.H"
  33. #include <stdlib.h>
  34. #include <string.h>
  35.  
  36. static int table_size;
  37.  
  38. void Fl::set_font(Fl_Font fnum, const char* name) {
  39.   if (fnum >= table_size) {
  40.     int i = table_size;
  41.     if (!i) {    // don't realloc the built-in table
  42.       table_size = 2*FL_FREE_FONT;
  43.       i = FL_FREE_FONT;
  44.       Fl_Fontdesc* t = (Fl_Fontdesc*)malloc(table_size*sizeof(Fl_Fontdesc));
  45.       memcpy(t, fl_fonts, FL_FREE_FONT*sizeof(Fl_Fontdesc));
  46.       fl_fonts = t;
  47.     } else {
  48.       table_size = 2*table_size;
  49.       fl_fonts=(Fl_Fontdesc*)realloc(fl_fonts, table_size*sizeof(Fl_Fontdesc));
  50.     }
  51.     for (; i < table_size; i++) fl_fonts[i].name = 0;
  52.   }
  53.   Fl_Fontdesc* s = fl_fonts+fnum;
  54.   if (s->name) {
  55.     if (!strcmp(s->name, name)) {s->name = name; return;}
  56. #ifndef WIN32
  57.     if (s->xlist && s->n >= 0) XFreeFontNames(s->xlist);
  58. #endif
  59.     for (Fl_FontSize* f = s->first; f;) {
  60.       Fl_FontSize* n = f->next; delete f; f = n;
  61.     }
  62.     s->first = 0;
  63.   }
  64.   s->name = name;
  65. #ifndef WIN32
  66.   s->xlist = 0;
  67. #endif
  68.   s->first = 0;
  69. }
  70.  
  71. const char* Fl::get_font(Fl_Font fnum) {return fl_fonts[fnum].name;}
  72.  
  73. //
  74. // End of "$Id: fl_set_font.cxx,v 1.5 1999/01/07 19:17:42 mike Exp $".
  75. //
  76.